package com.arch.dev.client.view;


import java.util.Set;

import com.arch.dev.client.CatagoryTable;
import com.arch.dev.client.controller.BudgetController;
import com.arch.dev.client.view.ui.BudgetImageBundle;
import com.arch.dev.client.view.ui.ImageButton;
import com.arch.dev.client.vo.CatagoryVO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.MultiSelectionModel;

public class CatagoryView extends Composite {

	@UiField
	public CatagoryTable catagoryTable;


	
	private static CatagoryViewUiBinder uiBinder = GWT
			.create(CatagoryViewUiBinder.class);

	interface CatagoryViewUiBinder extends UiBinder<Widget, CatagoryView> {
	}

	public CatagoryView() {

	
		initWidget(uiBinder.createAndBindUi(this));

				
		
		BudgetImageBundle bundle = (BudgetImageBundle) GWT

				.create(BudgetImageBundle.class);

		ImageButton deleteImageButton  = new ImageButton(null, bundle.getDeleteIcon());
		
		deleteImageButton.setTitle("Delete Records");

		deleteImageButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				MultiSelectionModel<CatagoryVO> multiSelectionModel = catagoryTable
						.getMultiSelectionModel();
				Set<CatagoryVO> catagoryVOs = multiSelectionModel.getSelectedSet();
				multiSelectionModel.clear();
				BudgetController.getInstance().deleteCatagoryValues(CatagoryView.this, catagoryVOs);

			}
		});
		ImageButton addImageButton  = new ImageButton(null, bundle.getAddIcon());
		
		final CatagoryDialogView catagoryDialogView = new CatagoryDialogView("Cancel", this);

		addImageButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				MultiSelectionModel<CatagoryVO> multiSelectionModel = catagoryTable
						.getMultiSelectionModel();
				Set<CatagoryVO> catagoryVOs = multiSelectionModel.getSelectedSet();
				multiSelectionModel.clear();
				catagoryDialogView.show();

			}
		});
		
		addImageButton.setTitle("Add Records");
		catagoryTable.addToolBarWidget(addImageButton);
		catagoryTable.addToolBarWidget(deleteImageButton);

	
		
		
	
	}

	

}
